home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue50 / IPC / Anonymous Pipes / API / ParentAnonymousPipeUnit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-28  |  1.2 KB  |  64 lines

  1. unit ParentAnonymousPipeUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes, Windows;
  7.  
  8. type
  9.   TTestAnonymousPipe = class(TThread)
  10.   private
  11.     FUIString: String;
  12.     FPipeHandle: THandle;
  13.     //Two routines to simplify showing our progress
  14.     procedure UpdateUI;
  15.     procedure WriteString(const S: String);
  16.   protected
  17.     //Body of the thread
  18.     procedure Execute; override;
  19.   public
  20.     constructor Create(PipeRead: THandle);
  21.   end;
  22.  
  23. implementation
  24.  
  25. uses
  26.   ParentMainFormUnit;
  27.  
  28. constructor TTestAnonymousPipe.Create(PipeRead: THandle);
  29. begin
  30.   inherited Create(False);
  31.   FPipeHandle := PipeRead;
  32. end;
  33.  
  34. procedure TTestAnonymousPipe.UpdateUI;
  35. begin
  36.   with Form1.Memo1 do
  37.     Text := Text + FUIString;
  38. end;
  39.  
  40. procedure TTestAnonymousPipe.WriteString(const S: String);
  41. begin
  42.   FUIString := S;
  43.   Synchronize(UpdateUI);
  44. end;
  45.  
  46. procedure TTestAnonymousPipe.Execute;
  47. const
  48.   BytesToRead = 1000;
  49. var
  50.   BytesRead: DWord;
  51.   DataBuf: array[0..BytesToRead] of Char;
  52. begin
  53.   while not Terminated and
  54.         ReadFile(FPipeHandle, DataBuf, BytesToRead, BytesRead, nil) do
  55.   begin
  56.     SetString(FUIString, DataBuf, BytesRead);
  57.     Synchronize(UpdateUI);
  58.   end;
  59.   if not Terminated then
  60.     WriteString('Pipe is broken')
  61. end;
  62.  
  63. end.
  64.